// pages/moneypage/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    date: '',
    show: false,
    minDate: new Date(2022, 0, 1).getTime(),
    userId: "",
    arrli: [],
    rightss: "rightss",
    right: "right",
    userinfo: "",
    createDate: '',
    isactive: 1,
    //年月
    currentDates:'',
    currentDate: new Date().getTime(),
    // minDate: new Date(2022).getTime(),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //获取月份
    let date = new Date(),
    year = date.getFullYear(), //获取完整的年份(4位)
	month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
	day = date.getDate() // 获取当前日(1-31)
	if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
	if (day < 10) day = `0${day}` // 如果日是个位数，在前面补0
 
  console.log(year+'-'+month)
  this.setData({
    currentDates: year+'-'+month
  })

    //获取userinfo
    this.data.userinfo = wx.getStorageSync('loginuser')
    this.setData({
      userinfo: wx.getStorageSync('loginuser')
    })
    this.data.userId = wx.getStorageSync('userId')
    // this.onConfirm()
    // // ------ 获取香灸金 ------
    wx.request({
      url: app.globalData.url+'/zkxj/user/xjjjf/list',
      data: {
        "createDate": this.data.currentDates,
        "currPage": 1,
        "pageSize": 20,
        "type": 1,
        "status":null,
        "userId": this.data.userId
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token')
      },
      success: (res) => {
        if (res.data.data) {
          this.setData({
            arrli: res.data.data
          })
        }
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  

  onInput(event) {
    let date = new Date(event.detail);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? ('0' + MM) : MM;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let m = date.getMinutes();
    m = m < 10 ? ('0' + m) : m;
    let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    let da=y + '-' + MM
    this.setData({
      currentDates:da ,
    });
    wx.request({
      url: app.globalData.url+'/zkxj/user/xjjjf/list',
      data: {
        "createDate": this.data.currentDates,
        "currPage": 1,
        "pageSize": 20,
        "type": 1,
        "status":null,
        "userId": this.data.userId
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token')
      },
      success: (res) => {
        if (res.data.data) {
          this.setData({
            arrli: res.data.data
          })
        }
        // console.log(res.data.data.list);
  
      },
    })
  },
  //跳转转化积分
  handletopscop() {
    wx.redirectTo({
      url: '/pages/exchange/index',
    })
  },
  //跳转提现
  handlemoney() {
    wx.navigateTo({
      url: '/pages/deposit/index',
    })
  },

  onDisplay() {
    this.setData({
      show: true
    });
  },
  onClose() {
    this.setData({
      show: false
    });
  },
  
  onConfirm(event) {
    var a = new Date()
    if (event) {
      this.setData({
        show: false,
        date: this.formatDate(event.detail),
      });
      wx.request({
        url: app.globalData.url+'/zkxj/user/xjjjf/list',
        data: {
          "createDate": this.data.currentDates,
          "currPage": 1,
          "pageSize": 20,
          "type": 1,
          "status":null,
          "userId": this.data.userId
        },
        method: 'POST',
        header: {
          'content-type': 'application/json',
          'token': wx.getStorageSync('token')
        },
        success: (res) => {
          if (res.data.data) {
            console.log(res.data.data);
            this.setData({
              arrli: res.data.data
            })
          }
          // console.log(res.data.data.list);

        },
      })
      console.log(this.data.date);

    } else {
      this.setData({
        show: false,
        date: this.formatDate(a),
      });
    }
  },
  //点击全部按钮切换
  handlechecklis() {
    this.setData({
      isactive: 1,
    })
    // ------ 获取香灸金 ------
    wx.request({
      url: app.globalData.url+'/zkxj/user/xjjjf/list',
      data: {
        "createDate": this.data.currentDates,
        "currPage": 1,
        "pageSize": 20,
        "status":null,
        "type": 1,
        "userId": this.data.userId
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token')
      },
      success: (res) => {
        console.log(res);
        if (res.data.data) {
          console.log(res.data.data);
          this.setData({
            arrli: res.data.data
          })
        }
        // console.log(res.data.data.list);

      },
    })
  },
  handlechecklisdao() {
    this.setData({
      isactive: 2,
    })
      // ------ 获取香灸金 ------
      wx.request({
        url: app.globalData.url+'/zkxj/user/xjjjf/list',
        data: {
          "createDate": this.data.currentDates,
          "currPage": 1,
          "pageSize": 20,
          "status":1,
          "type": 1,
          "userId": this.data.userId
        },
        method: 'POST',
        header: {
          'content-type': 'application/json',
          'token': wx.getStorageSync('token')
        },
        success: (res) => {
          console.log(res);
          if (res.data.data) {
            console.log(res.data.data);
            this.setData({
              arrli: res.data.data
            })
          }
          // console.log(res.data.data.list);
  
        },
      })
  },
  handlecheckliswei() {
    this.setData({
      isactive: 3,
    })
      // ------ 获取香灸金 ------
      wx.request({
        url: app.globalData.url+'/zkxj/user/xjjjf/list',
        data: {
          "createDate": this.data.currentDates,
          "currPage": 1,
          "pageSize": 20,
          "status":0,
          "type": 1,
          "userId": this.data.userId
        },
        method: 'POST',
        header: {
          'content-type': 'application/json',
          'token': wx.getStorageSync('token')
        },
        success: (res) => {
          console.log(res);
          if (res.data.data) {
            console.log(res.data.data);
            this.setData({
              arrli: res.data.data
            })
          }
          // console.log(res.data.data.list);
  
        },
      })
  },
  handletodetai() {
    wx.navigateTo({
      url: '/pages/xiangjiuti/index',
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // ------ 获取香灸金 ------
    wx.request({
      url: app.globalData.url+'/zkxj/user/xjjjf/list',
      data: {
        "createDate": this.data.currentDates,
        "currPage": 1,
        "pageSize": 20,
        "status":null,
        "type": 1,
        "userId": this.data.userId
      },
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'token': wx.getStorageSync('token')
      },
      success: (res) => {
        if (res.data.data) {
          this.setData({
            arrli: res.data.data
          })
        }
        // console.log(res.data.data.list);

      },
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})